//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ProvenanceCommon.Model
{

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Research.DataLayer;

    public class VersionHistoryModel
    {
        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>
        public string DisplayName { get; set; }

        /// <summary>
        /// Gets or sets the version.
        /// </summary>
        /// <value>The version.</value>
        public int Version { get; set; }

        /// <summary>
        /// Gets or sets ModifiedBy
        /// </summary>
        /// <value>The modified by.</value>
        public string ModifiedBy { get; set; }

        /// <summary>
        /// Gets or sets modified datatime.
        /// </summary>
        /// <value>The date and time.</value>
        public DateTime ModifiedDate { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="VersionHistoryModel"/> class.
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        public VersionHistoryModel(Activity workflow)
        {
            if (workflow == null)
            {
                throw new ArgumentNullException("workflow");
            }

            // Gets the display name.
            this.DisplayName = workflow.DisplayName;

            // Get the version of the workflow.
            this.Version = workflow.Version;

            // Get the updated user name.
            this.ModifiedBy = workflow.Updated.User;

            // Get the updated datetime.
            this.ModifiedDate = workflow.Updated.When;
        }

        /// <summary>
        /// Overridden tostring method. For automation Ids.
        /// </summary>
        /// <returns>The string representation of the object.</returns>
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(this.DisplayName))
            {
                return this.DisplayName;
            }
            return base.ToString();
        }
    }
}
